<!DOCTYPE html>
<html>
<head>
	<title>login</title>
	<script src="/js/jquery.js"></script>
</head>
<body>
<a href="/login.html">login</a>
<form id="register" method="post">
    <input type="email" name="email" required='required' placeHolder="email"><br>
    <input type="text" name="name" required='required' placeHolder="name"><br>
    <input type="password" name="password" required='required' placeHolder="password"><br>
    <input type="submit" value="register">
</form>
<p id="tips" style="display:none;"></p>

<script type="text/javascript">
$('document').ready(function(){
	$.fn.serializeObject = function() {
	    var o = {};
	    var a = this.serializeArray();
	    $.each(a, function() {
	        if (o[this.name] !== undefined) {
	            if (!o[this.name].push) {
	                o[this.name] = [o[this.name]];
	            }
	            o[this.name].push(this.value || '');
	        } else {
	            o[this.name] = this.value || '';
	        }
	    });
	    return o;
	};

	var nodeTip = $('#tips');
	$('#register').submit(function (e) { 
		console.log(e);
		var formData = $('form#register').serializeObject();
		console.log(formData);

		$.ajax({
            url: "/api/v1/vendor/register", 
            type: "POST", 
            headers: {"Content-Type": "application/json;charset=UTF-8"},
            data: JSON.stringify(formData), 
            success: function (res) { 
                // cb(null, res);
                console.log('success');
                window.location.href = "/login.html";
            }, 
            error: function (xhr) { 
                // cb(xhr.responseText);
				console.log(xhr.responseText);
				nodeTip.text(xhr.responseText);
				nodeTip.show();
            } 
        }); 
		console.log('aaaa');
		return false; 
	}); 
});
</script>

</body>
</html>